package com.webdesign.dto;

import java.util.List;

import org.apache.poi.ss.formula.functions.T;

public class MyPage {
	/** 每页显示条数默认为5条 */
	public static final int DEFAULT_SIZE = 5;

	/** 当前页码， 从1开始计 */
	private long number;

	/** 总条数 */
	private long totalElements;
	
	/** 总页数*/
	private long totalPages;
	
	/** 当前页数据 */
	private List<T> datas;
	
	/** 每页条数 */
	private int size;

	public MyPage() {
		// 设置默认值
		this.number = 1;
		this.size = DEFAULT_SIZE;
	}
	
	public long getNumber() {
		return number;
	}

	public void setNumber(long number) {
		this.number = number;
	}

	public long getTotalElements() {
		return totalElements;
	}

	public void setTotalElements(long totalElements) {
		this.totalElements = totalElements;
	}

	public long getTotalPages() {
		if(totalElements%DEFAULT_SIZE != 0){
			return totalElements/DEFAULT_SIZE + 1;
		}else{
			return totalElements/DEFAULT_SIZE;
		}
	}
	
	/** 获取每页显示条数 */
	public int getSize() {
		return size;
	}

	/** 设置每页显示条数 */
	public void setSize(int size) {
		this.size = size;
	}
	
	/** 获取从第几条数据开始查询 */
	public long getStart() {
		return (number-1) * size;
	}
	
	public long getEnd(){
		long i =getTotalElements() - getStart();
		if(i < getSize()){
			return getTotalElements();
		}else{
			return getStart() + getSize();
		}
	}
	
	/** 获取当前页数据 */
	public List<T> getDatas() {
		return datas;
	}

	/** 设置当前页数据 */
	public void setDatas(List<T> datas) {
		this.datas = datas;
	}

}
